//
//  ShopInfoViewController.m
//  Socrates
//
//  Created by shy on 15/4/11.
//  Copyright (c) 2015年 shy. All rights reserved.
//

#import "ShopInfoViewController.h"

#import "CircleImage.h"
#import "InfoCell.h"
#import "RDVTabBarController.h"

typedef enum {
    kUser_Info_honesty = 0,
    kUser_Info_joined,
    kUser_Info_created,
    kUser_Info_Section_Num,
} UserInfoSections;

@implementation ShopInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"商家详情";
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
    self.view.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    [self.tableView registerNib:[UINib nibWithNibName:@"InfoCell" bundle:nil] forCellReuseIdentifier:@"ShopInfoCellIdentifier"];
    [self configUpView];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)configUpView {
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGSize userImageSize = CGSizeMake(80, 80);
    CGFloat upViewHeight = 190;
    self.upViewBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, upViewHeight)];
    self.upViewBackground.image = [UIImage imageNamed:@"user_info_bg"];
    [self.imageView addSubview:self.upViewBackground];
    
    self.userImage = [[UIImageView alloc] initWithFrame:CGRectMake((width - userImageSize.width)/2, 30, userImageSize.width, userImageSize.height)];
    UIImage *userImage = [CircleImage circleImageWithName:@"angela_test" borderWidth:0. borderColor:[UIColor clearColor]];
    self.userImage.image = userImage;
    [self.imageView addSubview:self.userImage];
    
    self.userGender = [[UIImageView alloc] initWithFrame:CGRectMake(width/3, 130, 12, 17)];
    self.userGender.image = [UIImage imageNamed:@"female"];
    [self.imageView addSubview:self.userGender];
    
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(width/3 + 20, 130, width/3, 18)];
    self.userName.textAlignment = NSTextAlignmentLeft;
    self.userName.font = [UIFont systemFontOfSize:15.];
    self.userName.textColor = [UIColor blackColor];
    //    self.userName.backgroundColor = [UIColor purpleColor];
    self.userName.text = @"AngelaBaby";
    [self.imageView addSubview:self.userName];
    
    self.userSchool = [[UILabel alloc] initWithFrame:CGRectMake(width/4, 153, width/2, 18)];
    self.userSchool.textAlignment = NSTextAlignmentCenter;
    self.userSchool.font = [UIFont systemFontOfSize:14];
    self.userSchool.textColor = [UIColor grayColor];
    //    self.userSchool.backgroundColor = [UIColor purpleColor];
    self.userSchool.text = @"21岁 人民大学";
    [self.imageView addSubview:self.userSchool];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    switch (section) {
        case kUser_Info_honesty:
            return 15;
        case kUser_Info_joined:
            return 35;
        case kUser_Info_created:
            return 35;
        default:
            return 0;
    }
}

- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];
    view.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    UILabel *hint = [[UILabel alloc] initWithFrame:CGRectMake(23, 0, [UIScreen mainScreen].bounds.size.width, 40)];
    hint.textColor = [UIColor grayColor];
    hint.font = [UIFont systemFontOfSize:13.];
    [view addSubview:hint];
    switch (section) {
        case kUser_Info_honesty:
            
            break;
        case kUser_Info_joined:
            hint.text = @"ta 参加的";
            break;
        case kUser_Info_created:
            hint.text = @"ta 举办的";
            break;
        default:
            break;
    }
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch ([indexPath section]) {
        case kUser_Info_honesty:
            return 40;
        case kUser_Info_joined:
            return 80;
        case kUser_Info_created:
            return 80;
        default:
            return 0;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return kUser_Info_Section_Num;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = @"ShopInfoCellIdentifier";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    switch ([indexPath section]) {
        case kUser_Info_honesty:
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
            cell.textLabel.text = @"信誉度";
            cell.textLabel.textColor = [UIColor grayColor];
            cell.textLabel.font = [UIFont systemFontOfSize:15.];
            break;
        case kUser_Info_joined:
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
        case kUser_Info_created:
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}

@end
